package com.lyj.io.module.data.controller;

import com.lyj.io.annotation.SysLogAnnotation;
import com.lyj.io.common.dto.IdsDto;
import com.lyj.io.common.utils.PageUtils;
import com.lyj.io.common.utils.R;
import com.lyj.io.module.data.entity.TabFieldEntity;
import com.lyj.io.module.data.entity.TabsEntity;
import com.lyj.io.module.data.service.TabFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 模板字段相关api
 * @author 李亚杰
 * @email sunlightcs@gmail.com
 * @date 2021-09-13 11:27:20
 */
@Api(value = "TabFieldController", tags = "模型字段相关api")
@RestController
@RequestMapping("/api/v1/tabField")
public class TabFieldController {
    @Autowired
    private TabFieldService tabFieldService;

    /**
     * 根据模型id查询模型详情
     * @author: liyajie
     * @date: 2021/12/29 15:24
     * @param params
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("根据模型id查询模型详情")
    @ApiOperation(value = "根据模型id查询模型详情", notes = "根据模型id查询模型详情")
    @PostMapping("/getTabFieldlist")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = tabFieldService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 新增模型字段
     * @author: liyajie
     * @date: 2021/12/29 15:32
     * @param tabFieldEntity
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("新增模型字段")
    @ApiOperation(value = "新增模型字段", notes = "新增模型字段")
    @RequestMapping("/addTabField")
    public R save(@RequestBody TabFieldEntity tabFieldEntity) {
        tabFieldService.save(tabFieldEntity);
        return R.ok();
    }

    /**
     * 更新模型字段
     * @author: liyajie
     * @date: 2021/12/29 15:45
     * @param tabFieldEntity
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("更新模型字段")
    @ApiOperation(value = "更新模型字段", notes = "更新模型字段")
    @RequestMapping("/updateTabField")
    public R update(@RequestBody TabFieldEntity tabFieldEntity) {
        tabFieldService.updateById(tabFieldEntity);
        return R.ok();
    }

    /**
     * 删除模型字段
     * @author: liyajie
     * @date: 2021/12/29 15:46
     * @param idsDto
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("删除模型字段")
    @ApiOperation(value = "删除模型字段", notes = "删除模型字段")
    @RequestMapping("/delTabFiedl")
    public R delete(@RequestBody IdsDto idsDto) {
        String ids = idsDto.getIds();
        tabFieldService.removeByIds(Arrays.asList(ids.split(",")));
        return R.ok();
    }
}
